package com.xintonghua.bussiness.ui.user.amount;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xintonghua.bussiness.BuildConfig;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.event.BankEventBus;
import com.xintonghua.bussiness.util.MoneyEditText;
import com.xintonghua.bussiness.util.MyState;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：wanxianyi
 * 时间：2018/4/1.
 * 包名：com.xintonghua.bussiness.ui.user.amount
 */

public class WithdrawActivity extends BaseActivity {
    @BindView(R.id.ima_type)
    ImageView imaType;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.number)
    TextView number;
    @BindView(R.id.choose_card)
    RelativeLayout chooseCard;
    @BindView(R.id.m_card)
    RelativeLayout mCard;
    @BindView(R.id.money)
    MoneyEditText money;
    @BindView(R.id.kt_money)
    TextView ktMoney;
    @BindView(R.id.all_money)
    TextView allMoney;
    @BindView(R.id.confirm)
    TextView confirm;
    @BindView(R.id.lin_tx)
    LinearLayout linTx;
    @BindView(R.id.tv_des)
    TextView tv_des;
    String myMoney = "";
    private String bankName;
    private String bankId = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_withdraw);
        ButterKnife.bind(this);
        onSimpleActionBar();
        setSimpleActionBar("提现");
        EventBus.getDefault().register(this);
        Intent intent = getIntent();
        myMoney = intent.getStringExtra(BuildConfig.FLAVOR);
        ktMoney.setText("可提现金额" + myMoney + "元");
        httpCent.getTixianMoney(this, MyState.requestTwo);

    }

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        switch (order) {
            case MyState.requestOne:
                break;
            case MyState.requestTwo:
                double v = Double.valueOf(data.toString()) * 100;
                tv_des.setText("提现将收取" + v + "%的手续费" + "\n" + "次日24点前处理（除周末及国家法定假日外）");
                break;
        }
    }

    @OnClick({R.id.choose_card, R.id.all_money, R.id.confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.choose_card:
                openActivity(BankListActivity.class);
                break;
            case R.id.all_money:
                money.setText(myMoney);
                break;
            case R.id.confirm:
                if (isNull(getStr(money))) {
                    mToast("请入提现金额");
                    return;
                }
                if (Double.valueOf(getStr(money)) > Double.valueOf(myMoney)) {
                    mToast("请入正确金额");
                    return;
                }
                if (TextUtils.isEmpty(bankId)) {
                    mToast("请绑定账户");
                    return;
                }
                httpCent.saveCash("支付宝", bankId, bankName, myMoney, this, MyState.requestOne);
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(BankEventBus bankEventBus) {
        bankId = bankEventBus.getNo();
        bankName = bankEventBus.getName();
        number.setText(bankId);
    }

}
